/*
 * ============================================================================
 * Copyright Notice!
 * ----------------------------------------------------------------------------
 * This file contains proprietary and confidential information belonging to the
 * group of people involvled in developing this project.  Reproduction, disclosure 
 * or use without specific written authorization from project stake holders is 
 * prohibited. Please refer the readme.txt in project installation folder for more
 * specific contacts
 *
 * All rights reserved.
 * ============================================================================
 */
package edu.uwm.universitydb.service.student;

import java.util.List;

import edu.uwm.universitydb.dao.student.DeleteStudentCommand;
import edu.uwm.universitydb.dao.student.InsertStudentCommand;
import edu.uwm.universitydb.dao.student.SearchStudentBySSNCommand;
import edu.uwm.universitydb.dao.student.SearchStudentsByNameCommand;
import edu.uwm.universitydb.dao.student.UpdateStudentCommand;
import edu.uwm.universitydb.framework.exception.DataAccessException;
import edu.uwm.universitydb.model.Student;

/**
 * <code>StudentServiceImpl</type>
 * 
 * Base implementation of student service interface
 * 
 * @author Shyam Nair
 */
public class StudentServiceImpl implements StudentService
{

    /*
     * (non-javadoc)
     * @see edu.uwm.universitydb.service.student.StudentService#addStudent(edu.uwm.universitydb.model.Student)
     */
    @Override
    public boolean addStudent(final Student student) throws DataAccessException
    {
        final InsertStudentCommand insertCommand = new InsertStudentCommand(student);
        final int insertCount = insertCommand.executeCommand();
        return (insertCount > 0) ? true : false;
    }

    /*
     * (non-javadoc)
     * @see edu.uwm.universitydb.service.student.StudentService#removeStudent(java.lang.String)
     */
    @Override
    public boolean removeStudent(final String studentSSN)
    {

        try
        {
            final DeleteStudentCommand deleteCommand = new DeleteStudentCommand(studentSSN);
            final int deleteCount = deleteCommand.executeCommand();
            return (deleteCount > 0) ? true : false;
        }
        catch (final DataAccessException e)
        {
            e.printStackTrace();
            return false;
        }

    }

    /*
     * (non-javadoc)
     * @see edu.uwm.universitydb.service.student.StudentService#searchStudentByName(java.lang.String)
     */
    @Override
    public List<Student> searchStudentByName(final String name)
    {
        try
        {
            final SearchStudentsByNameCommand searchCommand = new SearchStudentsByNameCommand(name);
            return searchCommand.executeCommand();
        }
        catch (final DataAccessException dEx)
        {
            dEx.printStackTrace();
        }
        return null;
    }

    /*
     * (non-javadoc)
     * @see edu.uwm.universitydb.service.student.StudentService#getAllStudents()
     */
    @Override
    public List<Student> getAllStudents()
    {
        try
        {
            final SearchStudentsByNameCommand searchCommand = new SearchStudentsByNameCommand();
            return searchCommand.executeCommand();
        }
        catch (final DataAccessException dEx)
        {
            dEx.printStackTrace();
        }
        return null;
    }

    /*
     * (non-javadoc)
     * @see edu.uwm.universitydb.service.student.StudentService#getStudentBySSN(java.lang.String)
     */
    @Override
    public Student getStudentBySSN(final String ssn)
    {
        try
        {
            final SearchStudentBySSNCommand searchCommand = new SearchStudentBySSNCommand(ssn);
            return searchCommand.executeCommand();
        }
        catch (final DataAccessException dEx)
        {
            dEx.printStackTrace();
        }
        return null;
    }

	@Override
	public boolean updateStudent(Student student) throws DataAccessException {
		final UpdateStudentCommand updateCommand = new UpdateStudentCommand(student);
		final int updateCount = updateCommand.executeCommand();
		return (updateCount > 0) ? true : false;
	}

}

/*
 * ============================================================================
 * Change History
 * ----------------------------------------------------------------------------
 * Apr 19, 2014   Shyam Nair
 * File created
 * ----------------------------------------------------------------------------
 */